package ru.efimmatytsin.tweeterella.validators;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import ru.efimmatytsin.tweeterella.viewmodels.LoginFormViewModel;

/**
 * Created by Efim Matytsin on 22.02.15.
 */

@Component
public class LoginFormValidator implements Validator {
    @Override
    public boolean supports(Class<?> aClass) {
        return LoginFormViewModel.class.equals(aClass);
    }

    @Override
    public void validate(Object o, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors,"username","username.empty");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors,"password","password.empty");
    }
}
